<template>
	<div style="position: absolute; width: 100%; height: 100%;">
		<van-nav-bar title="我的收藏" left-text="返回" left-arrow @click-left="$router.back()" />
		<!-- 车辆列表 -->
		<usedcar-list :data="collection" @onBtnClick="onCarDetail"></usedcar-list>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				collection: []
			}
		},
		mounted() {
			this.onLoadCollection(this.$route.query.userId)
		},
		methods: {
			//加载用户收藏
			onLoadCollection(id) {
				let _this = this
				_this.$axios({
					method: 'post',
					url: '/collection/findAll',
					data: {
						id: id
					}
				}).then((resp) => {
					if (resp.code == 200) {
						let arr = []
						resp.data.forEach((val) => {
							arr.push(val.usedcar)
						})
						_this.collection = arr
					}
				})
			},
			//车辆详情
			onCarDetail(carId) {
				this.$router.push({
					path: "/page/detail",
					query: {
						id: carId
					}
				})
			}
		}

	}
</script>

<style scoped>
</style>
